package StudyCode.summary.BufferAndChannel;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CreateReadWriteMemoryMappedFile {
	public static void main(String[] argv) {
		try {
			File file = new File("filename");

			FileChannel rwChannel = new RandomAccessFile(file, "rw").getChannel();
			ByteBuffer wrBuf = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0,
					(int) rwChannel.size());
			System.out.println(wrBuf.toString());
			System.out.println("读写内存映射(memory-mapped)文件创建成功");
		} catch (IOException e) {
		}
	}
}
